import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


export default new Vuex.Store({
    state:{
        // isLogin:localStorage.hasOwnProperty('isLogin') ? Boolean(localStorage.getItem('isLogin')) : false,
        isLogin:localStorage.hasOwnProperty('isLogin') ? localStorage.getItem('isLogin') : '未登录',
        token:'',
    },
    mutations:{
        toLogin(state,token){
            localStorage.isLogin = '已登录';
            state.isLogin = '已登录';
            window.sessionStorage.setItem("token",token);
            state.token = token;
        },
        toLogout(state,token){
            localStorage.isLogin = '未登录';
            state.isLogin = '未登录';
            window.sessionStorage.removeItem("token",token);
            state.token = token;
        }
        // changeUsername(state,username){
        //     state.username = username;
        //     window.localStorage.setItem("username",username);
        // }
    }
});